.class public Lcom/glympse/platform/GFile;
.super Ljava/lang/Object;
.source "GFile.java"


# instance fields
.field private m_cap:Lcom/glympse/platform/common/CharArrayPointer;

.field private m_oOutputStream:Ljava/io/FileOutputStream;


# direct methods
.method public constructor <init>()V
    .locals 1

    .prologue
    const/4 v0, 0x0

    .line 23
    invoke-direct {p0}, Ljava/lang/Object;-><init>()V

    .line 25
    iput-object v0, p0, Lcom/glympse/platform/GFile;->m_oOutputStream:Ljava/io/FileOutputStream;

    .line 26
    iput-object v0, p0, Lcom/glympse/platform/GFile;->m_cap:Lcom/glympse/platform/common/CharArrayPointer;

    .line 23
    return-void
.end method

.method public static ReadFileToByteArray(Ljava/io/File;)[B
    .locals 10
    .parameter "oFile"

    .prologue
    const/4 v1, 0x0

    .line 157
    check-cast v1, [B

    .line 158
    .local v1, abBuffer:[B
    const/4 v6, 0x0

    .line 161
    .local v6, oStream:Ljava/io/FileInputStream;
    :try_start_0
    invoke-virtual {p0}, Ljava/io/File;->length()J

    move-result-wide v8

    long-to-int v4, v8

    .line 162
    .local v4, nLength:I
    new-array v1, v4, [B

    .line 163
    new-instance v7, Ljava/io/FileInputStream;

    invoke-direct {v7, p0}, Ljava/io/FileInputStream;-><init>(Ljava/io/File;)V
    :try_end_0
    .catchall {:try_start_0 .. :try_end_0} :catchall_0
    .catch Ljava/lang/Exception; {:try_start_0 .. :try_end_0} :catch_0

    .line 164
    .end local v6           #oStream:Ljava/io/FileInputStream;
    .local v7, oStream:Ljava/io/FileInputStream;
    const/4 v5, 0x0

    .line 165
    .local v5, nOffset:I
    :goto_0
    if-lt v5, v4, :cond_2

    .line 182
    :cond_0
    if-eqz v7, :cond_4

    .line 186
    :try_start_1
    invoke-virtual {v7}, Ljava/io/FileInputStream;->close()V
    :try_end_1
    .catch Ljava/lang/Exception; {:try_start_1 .. :try_end_1} :catch_3

    move-object v6, v7

    .line 195
    .end local v4           #nLength:I
    .end local v5           #nOffset:I
    .end local v7           #oStream:Ljava/io/FileInputStream;
    .restart local v6       #oStream:Ljava/io/FileInputStream;
    :cond_1
    :goto_1
    return-object v1

    .line 167
    .end local v6           #oStream:Ljava/io/FileInputStream;
    .restart local v4       #nLength:I
    .restart local v5       #nOffset:I
    .restart local v7       #oStream:Ljava/io/FileInputStream;
    :cond_2
    sub-int v8, v4, v5

    :try_start_2
    invoke-virtual {v7, v1, v5, v8}, Ljava/io/FileInputStream;->read([BII)I
    :try_end_2
    .catchall {:try_start_2 .. :try_end_2} :catchall_1
    .catch Ljava/lang/Exception; {:try_start_2 .. :try_end_2} :catch_4

    move-result v3

    .line 168
    .local v3, nCount:I
    if-ltz v3, :cond_0

    .line 172
    add-int/2addr v5, v3

    goto :goto_0

    .line 175
    .end local v3           #nCount:I
    .end local v4           #nLength:I
    .end local v5           #nOffset:I
    .end local v7           #oStream:Ljava/io/FileInputStream;
    .restart local v6       #oStream:Ljava/io/FileInputStream;
    :catch_0
    move-exception v8

    move-object v2, v8

    .line 177
    .local v2, e:Ljava/lang/Exception;
    :goto_2
    :try_start_3
    new-instance v8, Ljava/lang/StringBuilder;

    const-string v9, "ReadFileToByteArray failed to read "

    invoke-direct {v8, v9}, Ljava/lang/StringBuilder;-><init>(Ljava/lang/String;)V

    invoke-virtual {p0}, Ljava/io/File;->getAbsolutePath()Ljava/lang/String;

    move-result-object v9

    invoke-virtual {v8, v9}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v8

    invoke-virtual {v8}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v8

    invoke-static {v8}, Lcom/glympse/platform/common/Helpers;->Log(Ljava/lang/String;)V

    .line 178
    const/4 v8, 0x0

    move-object v0, v8

    check-cast v0, [B

    move-object v1, v0
    :try_end_3
    .catchall {:try_start_3 .. :try_end_3} :catchall_0

    .line 182
    if-eqz v6, :cond_1

    .line 186
    :try_start_4
    invoke-virtual {v6}, Ljava/io/FileInputStream;->close()V
    :try_end_4
    .catch Ljava/lang/Exception; {:try_start_4 .. :try_end_4} :catch_1

    goto :goto_1

    .line 188
    :catch_1
    move-exception v2

    .line 190
    invoke-static {v2}, Lcom/glympse/platform/common/Helpers;->Log(Ljava/lang/Throwable;)V

    goto :goto_1

    .line 181
    .end local v2           #e:Ljava/lang/Exception;
    :catchall_0
    move-exception v8

    .line 182
    :goto_3
    if-eqz v6, :cond_3

    .line 186
    :try_start_5
    invoke-virtual {v6}, Ljava/io/FileInputStream;->close()V
    :try_end_5
    .catch Ljava/lang/Exception; {:try_start_5 .. :try_end_5} :catch_2

    .line 193
    :cond_3
    :goto_4
    throw v8

    .line 188
    :catch_2
    move-exception v2

    .line 190
    .restart local v2       #e:Ljava/lang/Exception;
    invoke-static {v2}, Lcom/glympse/platform/common/Helpers;->Log(Ljava/lang/Throwable;)V

    goto :goto_4

    .line 188
    .end local v2           #e:Ljava/lang/Exception;
    .end local v6           #oStream:Ljava/io/FileInputStream;
    .restart local v4       #nLength:I
    .restart local v5       #nOffset:I
    .restart local v7       #oStream:Ljava/io/FileInputStream;
    :catch_3
    move-exception v2

    .line 190
    .restart local v2       #e:Ljava/lang/Exception;
    invoke-static {v2}, Lcom/glympse/platform/common/Helpers;->Log(Ljava/lang/Throwable;)V

    .end local v2           #e:Ljava/lang/Exception;
    :cond_4
    move-object v6, v7

    .end local v7           #oStream:Ljava/io/FileInputStream;
    .restart local v6       #oStream:Ljava/io/FileInputStream;
    goto :goto_1

    .line 181
    .end local v6           #oStream:Ljava/io/FileInputStream;
    .restart local v7       #oStream:Ljava/io/FileInputStream;
    :catchall_1
    move-exception v8

    move-object v6, v7

    .end local v7           #oStream:Ljava/io/FileInputStream;
    .restart local v6       #oStream:Ljava/io/FileInputStream;
    goto :goto_3

    .line 175
    .end local v6           #oStream:Ljava/io/FileInputStream;
    .restart local v7       #oStream:Ljava/io/FileInputStream;
    :catch_4
    move-exception v8

    move-object v2, v8

    move-object v6, v7

    .end local v7           #oStream:Ljava/io/FileInputStream;
    .restart local v6       #oStream:Ljava/io/FileInputStream;
    goto :goto_2
.end method

.method public static ReadFileToByteArray(Ljava/lang/String;)[B
    .locals 4
    .parameter "strName"

    .prologue
    .line 148
    sget-object v1, Lcom/glympse/platform/Platform;->m_oContext:Landroid/content/Context;

    new-instance v2, Ljava/lang/StringBuilder;

    invoke-static {p0}, Ljava/lang/String;->valueOf(Ljava/lang/Object;)Ljava/lang/String;

    move-result-object v3

    invoke-direct {v2, v3}, Ljava/lang/StringBuilder;-><init>(Ljava/lang/String;)V

    const-string v3, ".txt"

    invoke-virtual {v2, v3}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v2

    invoke-virtual {v2}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v2

    invoke-virtual {v1, v2}, Landroid/content/Context;->getFileStreamPath(Ljava/lang/String;)Ljava/io/File;

    move-result-object v0

    .line 151
    .local v0, oFile:Ljava/io/File;
    invoke-static {v0}, Lcom/glympse/platform/GFile;->ReadFileToByteArray(Ljava/io/File;)[B

    move-result-object v1

    return-object v1
.end method


# virtual methods
.method public Close()V
    .locals 3

    .prologue
    const/4 v2, 0x0

    .line 76
    iget-object v1, p0, Lcom/glympse/platform/GFile;->m_oOutputStream:Ljava/io/FileOutputStream;

    if-eqz v1, :cond_0

    .line 80
    :try_start_0
    iget-object v1, p0, Lcom/glympse/platform/GFile;->m_oOutputStream:Ljava/io/FileOutputStream;

    invoke-virtual {v1}, Ljava/io/FileOutputStream;->close()V
    :try_end_0
    .catch Ljava/lang/Exception; {:try_start_0 .. :try_end_0} :catch_0

    .line 86
    :goto_0
    iput-object v2, p0, Lcom/glympse/platform/GFile;->m_oOutputStream:Ljava/io/FileOutputStream;

    .line 89
    :cond_0
    iput-object v2, p0, Lcom/glympse/platform/GFile;->m_cap:Lcom/glympse/platform/common/CharArrayPointer;

    .line 90
    return-void

    .line 82
    :catch_0
    move-exception v1

    move-object v0, v1

    .line 84
    .local v0, e:Ljava/lang/Exception;
    invoke-static {v0}, Lcom/glympse/platform/common/Helpers;->Log(Ljava/lang/Throwable;)V

    goto :goto_0
.end method

.method public OpenForInput(Ljava/lang/String;)Z
    .locals 3
    .parameter "strName"

    .prologue
    .line 52
    invoke-virtual {p0}, Lcom/glympse/platform/GFile;->Close()V

    .line 57
    :try_start_0
    invoke-static {p1}, Lcom/glympse/platform/GFile;->ReadFileToByteArray(Ljava/lang/String;)[B

    move-result-object v0

    .line 58
    .local v0, abFile:[B
    if-eqz v0, :cond_0

    .line 61
    new-instance v2, Lcom/glympse/platform/common/CharArrayPointer;

    invoke-direct {v2, v0}, Lcom/glympse/platform/common/CharArrayPointer;-><init>([B)V

    iput-object v2, p0, Lcom/glympse/platform/GFile;->m_cap:Lcom/glympse/platform/common/CharArrayPointer;
    :try_end_0
    .catch Ljava/lang/Exception; {:try_start_0 .. :try_end_0} :catch_0

    .line 62
    const/4 v2, 0x1

    .line 70
    .end local v0           #abFile:[B
    :goto_0
    return v2

    .line 65
    :catch_0
    move-exception v2

    move-object v1, v2

    .line 67
    .local v1, e:Ljava/lang/Exception;
    invoke-static {v1}, Lcom/glympse/platform/common/Helpers;->Log(Ljava/lang/Throwable;)V

    .line 70
    .end local v1           #e:Ljava/lang/Exception;
    :cond_0
    const/4 v2, 0x0

    goto :goto_0
.end method

.method public OpenForOutput(Ljava/lang/String;)Z
    .locals 5
    .parameter "strName"

    .prologue
    const/4 v4, 0x0

    .line 31
    invoke-virtual {p0}, Lcom/glympse/platform/GFile;->Close()V

    .line 35
    :try_start_0
    sget-object v1, Lcom/glympse/platform/Platform;->m_oContext:Landroid/content/Context;

    new-instance v2, Ljava/lang/StringBuilder;

    invoke-static {p1}, Ljava/lang/String;->valueOf(Ljava/lang/Object;)Ljava/lang/String;

    move-result-object v3

    invoke-direct {v2, v3}, Ljava/lang/StringBuilder;-><init>(Ljava/lang/String;)V

    const-string v3, ".txt"

    invoke-virtual {v2, v3}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v2

    invoke-virtual {v2}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v2

    const/4 v3, 0x0

    invoke-virtual {v1, v2, v3}, Landroid/content/Context;->openFileOutput(Ljava/lang/String;I)Ljava/io/FileOutputStream;

    move-result-object v1

    iput-object v1, p0, Lcom/glympse/platform/GFile;->m_oOutputStream:Ljava/io/FileOutputStream;

    .line 36
    iget-object v1, p0, Lcom/glympse/platform/GFile;->m_oOutputStream:Ljava/io/FileOutputStream;
    :try_end_0
    .catch Ljava/lang/Exception; {:try_start_0 .. :try_end_0} :catch_0

    if-eqz v1, :cond_0

    .line 38
    const/4 v1, 0x1

    .line 46
    :goto_0
    return v1

    .line 41
    :catch_0
    move-exception v1

    move-object v0, v1

    .line 43
    .local v0, e:Ljava/lang/Exception;
    invoke-static {v0}, Lcom/glympse/platform/common/Helpers;->Log(Ljava/lang/Throwable;)V

    .end local v0           #e:Ljava/lang/Exception;
    :cond_0
    move v1, v4

    .line 46
    goto :goto_0
.end method

.method public ReadLine()Lcom/glympse/platform/GVector$NameValueNodes;
    .locals 2

    .prologue
    .line 115
    const/4 v0, 0x0

    .line 117
    .local v0, listNameValues:Lcom/glympse/platform/GVector$NameValueNodes;,"Lcom/glympse/platform/GVector$NameValueNodes;"
    :cond_0
    if-nez v0, :cond_1

    iget-object v1, p0, Lcom/glympse/platform/GFile;->m_cap:Lcom/glympse/platform/common/CharArrayPointer;

    if-eqz v1, :cond_1

    iget-object v1, p0, Lcom/glympse/platform/GFile;->m_cap:Lcom/glympse/platform/common/CharArrayPointer;

    invoke-virtual {v1}, Lcom/glympse/platform/common/CharArrayPointer;->IsEnd()Z

    move-result v1

    if-eqz v1, :cond_2

    .line 141
    :cond_1
    return-object v0

    .line 120
    :cond_2
    iget-object v1, p0, Lcom/glympse/platform/GFile;->m_cap:Lcom/glympse/platform/common/CharArrayPointer;

    invoke-static {v1}, Lcom/glympse/platform/common/Helpers;->ParseNameValuePairs(Lcom/glympse/platform/common/CharArrayPointer;)Lcom/glympse/platform/GVector$NameValueNodes;

    move-result-object v0

    .line 123
    if-eqz v0, :cond_3

    invoke-virtual {v0}, Lcom/glympse/platform/GVector$NameValueNodes;->isEmpty()Z

    move-result v1

    if-eqz v1, :cond_4

    .line 125
    :cond_3
    const/4 v0, 0x0

    .line 129
    :cond_4
    :goto_0
    iget-object v1, p0, Lcom/glympse/platform/GFile;->m_cap:Lcom/glympse/platform/common/CharArrayPointer;

    invoke-virtual {v1}, Lcom/glympse/platform/common/CharArrayPointer;->IsLineEnd()Z

    move-result v1

    if-eqz v1, :cond_5

    .line 135
    :goto_1
    iget-object v1, p0, Lcom/glympse/platform/GFile;->m_cap:Lcom/glympse/platform/common/CharArrayPointer;

    invoke-virtual {v1}, Lcom/glympse/platform/common/CharArrayPointer;->IsSpace()Z

    move-result v1

    if-eqz v1, :cond_0

    .line 137
    iget-object v1, p0, Lcom/glympse/platform/GFile;->m_cap:Lcom/glympse/platform/common/CharArrayPointer;

    invoke-virtual {v1}, Lcom/glympse/platform/common/CharArrayPointer;->Inc()V

    goto :goto_1

    .line 131
    :cond_5
    iget-object v1, p0, Lcom/glympse/platform/GFile;->m_cap:Lcom/glympse/platform/common/CharArrayPointer;

    invoke-virtual {v1}, Lcom/glympse/platform/common/CharArrayPointer;->Inc()V

    goto :goto_0
.end method

.method public WriteLine(Ljava/lang/String;)Z
    .locals 4
    .parameter "strLine"

    .prologue
    .line 95
    iget-object v1, p0, Lcom/glympse/platform/GFile;->m_oOutputStream:Ljava/io/FileOutputStream;

    if-eqz v1, :cond_0

    .line 99
    :try_start_0
    iget-object v1, p0, Lcom/glympse/platform/GFile;->m_oOutputStream:Ljava/io/FileOutputStream;

    const-string v2, "UTF-8"

    invoke-virtual {p1, v2}, Ljava/lang/String;->getBytes(Ljava/lang/String;)[B

    move-result-object v2

    invoke-virtual {v1, v2}, Ljava/io/FileOutputStream;->write([B)V

    .line 100
    iget-object v1, p0, Lcom/glympse/platform/GFile;->m_oOutputStream:Ljava/io/FileOutputStream;

    const-string v2, "\r\n"

    const-string v3, "UTF-8"

    invoke-virtual {v2, v3}, Ljava/lang/String;->getBytes(Ljava/lang/String;)[B

    move-result-object v2

    invoke-virtual {v1, v2}, Ljava/io/FileOutputStream;->write([B)V
    :try_end_0
    .catch Ljava/lang/Exception; {:try_start_0 .. :try_end_0} :catch_0

    .line 101
    const/4 v1, 0x1

    .line 109
    :goto_0
    return v1

    .line 103
    :catch_0
    move-exception v1

    move-object v0, v1

    .line 105
    .local v0, e:Ljava/lang/Exception;
    invoke-static {v0}, Lcom/glympse/platform/common/Helpers;->Log(Ljava/lang/Throwable;)V

    .line 109
    .end local v0           #e:Ljava/lang/Exception;
    :cond_0
    const/4 v1, 0x0

    goto :goto_0
.end method
